home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / MiniGames / PTB / PushTheBusMG.as
Encoding:
Text File  |  2013-04-24  |  5.6 KB  |  185 lines

  1. class MiniGames.PTB.PushTheBusMG extends MiniGames.BaseMiniGame
  2. {
  3.    var nDone;
  4.    var bModeSandy;
  5.    var nRange;
  6.    var nNumberTimes;
  7.    var nNextDir;
  8.    var mcRef;
  9.    var nPosX;
  10.    var sState;
  11.    var bOver;
  12.    static var sSTATE_SANDY = "Sandy";
  13.    static var sSTATE_BOB = "SpongeBob";
  14.    static var sSTATE_SANDY_WHACKY = "SandyWhacky";
  15.    static var sSTATE_BOB_WHACKY = "BobWhacky";
  16.    static var nDIR_LEFT = 1;
  17.    static var nDIR_RIGHT = 2;
  18.    static var nTIME_TO_PUSH_SANDY = 40;
  19.    static var nTIME_TO_PUSH_BOB = 70;
  20.    static var nMAX_TIME = 16;
  21.    static var nSECOND_VALUE = 100;
  22.    static var nRANGE_SANDY = 40;
  23.    static var nRANGE_BOB = 40;
  24.    function PushTheBusMG(_mcRef)
  25.    {
  26.       super(_mcRef);
  27.       this.nDone = 0;
  28.       if(CTRLGame.getRef().Level == CTRLGame.nLEVEL1)
  29.       {
  30.          this.bModeSandy = true;
  31.          this.nRange = MiniGames.PTB.PushTheBusMG.nRANGE_SANDY;
  32.          this.nNumberTimes = MiniGames.PTB.PushTheBusMG.nTIME_TO_PUSH_SANDY;
  33.       }
  34.       else
  35.       {
  36.          this.bModeSandy = false;
  37.          this.nRange = MiniGames.PTB.PushTheBusMG.nRANGE_BOB;
  38.          this.nNumberTimes = MiniGames.PTB.PushTheBusMG.nTIME_TO_PUSH_BOB;
  39.       }
  40.       this.nNextDir = MiniGames.PTB.PushTheBusMG.nDIR_LEFT;
  41.       this.showInstructions();
  42.    }
  43.    function initMiniGame()
  44.    {
  45.       this.mcRef.mcState.mcMode.mcBus.mcStrenght.gotoAndStop(this.mcRef.mcState.mcStrenght._totalframes);
  46.       this.nPosX = 300;
  47.    }
  48.    function calculateScore()
  49.    {
  50.       this.addScoreFromTimeLeft(MiniGames.PTB.PushTheBusMG.nMAX_TIME,MiniGames.PTB.PushTheBusMG.nSECOND_VALUE);
  51.    }
  52.    function validateEndMiniGame()
  53.    {
  54.       if(this.nDone >= this.nNumberTimes)
  55.       {
  56.          this.setVictory();
  57.       }
  58.    }
  59.    function setState(_sState)
  60.    {
  61.       super.setState(_sState);
  62.       this.setPlayCharacter();
  63.    }
  64.    function doPause()
  65.    {
  66.       super.doPause();
  67.       if(this.sState == MiniGames.BaseMiniGame.sSTATE_MINIGAME)
  68.       {
  69.          this.mcRef.mcState.mcBus.stop();
  70.       }
  71.       else if(this.sState == MiniGames.BaseMiniGame.sSTATE_VICTORY)
  72.       {
  73.          this.mcRef.mcState.mcMode.stop();
  74.          this.mcRef.mcState.mcMode.mcBus.stop();
  75.       }
  76.    }
  77.    function doUnPause()
  78.    {
  79.       super.doUnPause();
  80.       this.mcRef.mcState.stop();
  81.       if(this.sState == MiniGames.BaseMiniGame.sSTATE_MINIGAME)
  82.       {
  83.          this.mcRef.mcState.mcBus.play();
  84.       }
  85.       else if(this.sState == MiniGames.BaseMiniGame.sSTATE_VICTORY)
  86.       {
  87.          this.mcRef.mcState.mcMode.play();
  88.          this.mcRef.mcState.mcMode.mcBus.play();
  89.       }
  90.    }
  91.    function setPlayCharacter()
  92.    {
  93.       if(this.bModeSandy)
  94.       {
  95.          if(Main.getRef().isCheatClothesActivated())
  96.          {
  97.             this.mcRef.mcState.gotoAndStop(MiniGames.PTB.PushTheBusMG.sSTATE_SANDY_WHACKY);
  98.          }
  99.          else
  100.          {
  101.             this.mcRef.mcState.gotoAndStop(MiniGames.PTB.PushTheBusMG.sSTATE_SANDY);
  102.          }
  103.       }
  104.       else if(Main.getRef().isCheatClothesActivated())
  105.       {
  106.          this.mcRef.mcState.gotoAndStop(MiniGames.PTB.PushTheBusMG.sSTATE_BOB_WHACKY);
  107.       }
  108.       else
  109.       {
  110.          this.mcRef.mcState.gotoAndStop(MiniGames.PTB.PushTheBusMG.sSTATE_BOB);
  111.       }
  112.       var _loc2_ = this.mcRef.mcState.mcMode.mcBus.mcStrenght._totalframes / this.nNumberTimes * this.nDone;
  113.       this.mcRef.mcState.mcMode.mcBus.mcStrenght.gotoAndStop(100 - Math.round(_loc2_));
  114.    }
  115.    function onKeyPressed()
  116.    {
  117.       this.nDone = this.nDone + 1;
  118.       var _loc2_ = this.mcRef.mcState.mcMode.mcBus.mcStrenght._totalframes / this.nNumberTimes * this.nDone;
  119.       this.mcRef.mcState.mcMode.mcBus.mcStrenght.gotoAndStop(100 - Math.round(_loc2_));
  120.    }
  121.    function validateActions()
  122.    {
  123.       if(!Controller.getRef().isPaused())
  124.       {
  125.          if(this.nNextDir == MiniGames.PTB.PushTheBusMG.nDIR_LEFT)
  126.          {
  127.             if(CTRLGame.getRef().mcRef._xmouse <= this.nPosX - this.nRange)
  128.             {
  129.                this.onKeyPressed();
  130.                this.nNextDir = MiniGames.PTB.PushTheBusMG.nDIR_RIGHT;
  131.             }
  132.          }
  133.          else if(this.nNextDir == MiniGames.PTB.PushTheBusMG.nDIR_RIGHT)
  134.          {
  135.             if(CTRLGame.getRef().mcRef._xmouse >= this.nPosX + this.nRange)
  136.             {
  137.                this.nNextDir = MiniGames.PTB.PushTheBusMG.nDIR_LEFT;
  138.                this.onKeyPressed();
  139.             }
  140.          }
  141.       }
  142.    }
  143.    function setVictory()
  144.    {
  145.       this.setState(MiniGames.BaseMiniGame.sSTATE_VICTORY);
  146.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  147.       this.mcRef.mcState.mcMode.mcBus.mcStrenght.stop();
  148.       Controller.getRef().getSounds().playSound("alguaetore",Controller.nSFX_VOLUME,1);
  149.    }
  150.    function HowToPlayIn()
  151.    {
  152.       if(this.mcRef.mcState.mcMode._currentframe == this.mcRef.mcState.mcMode._totalframes)
  153.       {
  154.          this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IDLE);
  155.          this.initSkipKeys();
  156.       }
  157.    }
  158.    function HowToPlayIdle()
  159.    {
  160.       if(this.mcRef.mcState.mcMode._currentframe == this.mcRef.mcState.mcMode._totalframes)
  161.       {
  162.          this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_OUT);
  163.       }
  164.    }
  165.    function HowToPlayOut()
  166.    {
  167.       if(this.mcRef.mcState.mcMode._currentframe == this.mcRef.mcState.mcMode._totalframes)
  168.       {
  169.          this.startGame();
  170.       }
  171.    }
  172.    function MiniGame()
  173.    {
  174.       super.MiniGame();
  175.       this.validateActions();
  176.    }
  177.    function Victory()
  178.    {
  179.       if(this.mcRef.mcState.mcMode._currentframe == this.mcRef.mcState.mcMode._totalframes - 15)
  180.       {
  181.          this.bOver = true;
  182.       }
  183.    }
  184. }
  185.